import React from 'react';
import NavbarLayout from '@theme/Navbar/Layout';
import NavbarContent from '@theme/Navbar/Content';
import clsx from 'clsx';
import { useLocation } from 'react-router-dom';
import style from './style.module.css';

export default function NavBar(): JSX.Element {
  const location = useLocation();

  const isActive = (path) => {
    return location.pathname.startsWith(path);
  };

  const isIntroActive = () => {
    return isActive('/docs') && !isActive('/docs/openapi/');
  };
  return (
    <>
      <NavbarLayout>
        <NavbarContent />
      </NavbarLayout>
      <nav className={style.nav}>
        <div className={style.navContent}>
          <a
            className={clsx(style.navItem, isIntroActive() && style.active)}
            href="/docs"
          >
            使用指南
          </a>
          <a
            className={clsx(
              style.navItem,
              isActive('/docs/openapi/v1') && style.active,
            )}
            href="/docs/openapi/v1"
          >
            接口文档
          </a>
        </div>
      </nav>
    </>
  );
}
